package lia.util;

import java.util.HashMap;
import java.util.Map;

/**
 * index config
 * 
 * @author F.H Dragon(wenlong.meng@gmail.com)
 * @version 1.0 at 2011/08/06
 * @since 1.0
 */
public class IndexConfig {

	//local variables
	/**
	 * name
	 */
	private String name;
	/**
	 * comment
	 */
	private String comment;
	/**
	 * documents config
	 */
	private Map<String, DocumentConfig> docs = new HashMap<String, DocumentConfig>();
	/**
	 * field config
	 */
	public FieldConfig field;
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the comment
	 */
	public String getComment() {
		return comment;
	}
	/**
	 * @param comment the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}
	
	/**
	 * @return the docs
	 */
	public Map<String, DocumentConfig> getDocs() {
		return docs;
	}
	/**
	 * @param docs the docs to set
	 */
	public void setDocs(Map<String, DocumentConfig> docs) {
		this.docs = docs;
	}
	/**
	 * @param doc the docs to set
	 */
	public void setDoc(DocumentConfig doc) {
		this.docs.put(doc.getName(), doc);
	}
	
	/**
	 * @param configDocName the document to set
	 */
	public DocumentConfig document(String name) {
		return this.docs.get(name);
	}
	
	/**
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "IndexConfig [" + (name != null ? "name=" + name + ", " : "")
				+ (comment != null ? "comment=" + comment + ", " : "")
				+ (docs != null ? "docs=" + docs + ", " : "")
				+ (field != null ? "field=" + field : "") + "]";
	}

	/**
	 * the config of field
	 * 
	 * @author F.H Dragon(wenlong.meng@gmail.com)
	 * @version 1.0 at 2011/08/06
	 * @since 1.0
	 */
	public static class FieldConfig {
		
		//local variables
		/**
		 * name
		 */
		private String name;
		/**
		 * comment
		 */
		private String comment;
		/**
		 * Filed index
		 */
		public org.apache.lucene.document.Field.Index index;
		/**
		 * Filed store
		 */
		public org.apache.lucene.document.Field.Store store;
		/**
		 * Filed TermVector
		 */
		private org.apache.lucene.document.Field.TermVector termVector;
		
		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}
		/**
		 * @param name the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}
		
		/**
		 * @return the comment
		 */
		public String getComment() {
			return comment;
		}
		/**
		 * @param comment the comment to set
		 */
		public void setComment(String comment) {
			this.comment = comment;
		}
		
		/**
		 * @return the index
		 */
		public org.apache.lucene.document.Field.Index getIndex() {
			return index;
		}
		/**
		 * @param index the index to set
		 */
		public void setIndex(org.apache.lucene.document.Field.Index index) {
			this.index = index;
		}
		
		/**
		 * @return the store
		 */
		public org.apache.lucene.document.Field.Store getStore() {
			return store;
		}
		/**
		 * @param store the store to set
		 */
		public void setStore(org.apache.lucene.document.Field.Store store) {
			this.store = store;
		}
		
		/**
		 * @return the termVector
		 */
		public org.apache.lucene.document.Field.TermVector getTermVector() {
			return termVector;
		}
		/**
		 * @param termVector the termVector to set
		 */
		public void setTermVector(org.apache.lucene.document.Field.TermVector termVector) {
			this.termVector = termVector;
		}
		
		/**
		 * (non-Javadoc)
		 * @see java.lang.Object#toString()
		 */
		@Override
		public String toString() {
			return "FiledConfig ["
					+ (name != null ? "name=" + name + ", " : "")
					+ (comment != null ? "comment=" + comment + ", " : "")
					+ (index != null ? "index=" + index + ", " : "")
					+ (store != null ? "store=" + store + ", " : "")
					+ (termVector != null ? "termVector=" + termVector : "")
					+ "]";
		}
		
	}
	
	/**
	 * the config of document
	 * 
	 * @author F.H Dragon(wenlong.meng@gmail.com)
	 * @version 1.0 at 2011/08/06
	 * @since 1.0
	 */
	public static class DocumentConfig{
		
		//local variables
		/**
		 * name
		 */
		private String name;
		/**
		 * comment
		 */
		private String comment;
		/**
		 * document config
		 */
		private Map<String, FieldConfig> fields = new HashMap<String, FieldConfig>();

		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}
		/**
		 * @param name the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}

		/**
		 * @return the comment
		 */
		public String getComment() {
			return comment;
		}
		/**
		 * @param comment the comment to set
		 */
		public void setComment(String comment) {
			this.comment = comment;
		}

		/**
		 * @return the fields
		 */
		public Map<String, FieldConfig> getFields() {
			return fields;
		}
		/**
		 * @param fields the fields to set
		 */
		public void setFields(Map<String, FieldConfig> fields) {
			this.fields = fields;
		}
		/**
		 * @param field the fields to set
		 */
		public void setField(FieldConfig field) {
			this.fields.put(field.getName(), field);
		}
		
		/**
		 * build field config by name
		 * 
		 * @param name
		 * @return
		 */
		public FieldConfig field(String name){
			return this.fields.get(name);
		}
		
		/**
		 * (non-Javadoc)
		 * @see java.lang.Object#toString()
		 */
		@Override
		public String toString() {
			return "DocumentConfig ["
					+ (name != null ? "name=" + name + ", " : "")
					+ (comment != null ? "comment=" + comment + ", " : "")
					+ (fields != null ? "fields=" + fields : "") + "]";
		}
		
	}
	
}
